"use server";
import { load } from "cheerio";
import axios from "axios";
export const getBookContent = async (url: string) => {
    // const end = 6052;
  const end = 4000;
  const bookList = [];
  //   const end = 6052;
  for (let i = 5000; i <= 6052; i++) {
    const pageUrl = `${url}/${i}.html`;
    try {
      const result = await axios.get(pageUrl);
      let $ = load(result.data);
      const title = $("h1.wap_none").text();
      const cont = $("#chaptercontent").text();
      bookList.push({
        title,
        cont: cont.split("请收藏本站")[0],
      });
    } catch (error) {
      console.error(`Error fetching page ${i}:`, error);
    }
  }
  return bookList;
};
